package gui.controller;

/**
 * author:          alexander
 * version:         1.0
 * *************************************************
 * ** CreationDate:  12/15/12 9:09 PM
 * ** Project:       Leertaak 4 Mobile Robot Explorer
 * ** Package:       gui.controller
 * ** Classname:     DelayController
 * *************************************************
 */

import model.environment.Environment;
import model.robot.MobileRobot;

import javax.swing.*;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
import java.awt.*;


/**
 * author:          alexander
 * version:         1.0
 * *************************************************
 * ** CreationDate:  12/14/12 6:44 PM
 * ** Project:       Leertaak 4 Mobile Robot Explorer
 * ** Package:       gui.controller
 * ** Classname:     SimulationController
 * *************************************************
 */
public class DelayController extends JMenu implements ChangeListener {
	private JSlider speed;

	private final Environment environment;


	public DelayController(Environment environment) {
		super("Delay");

		this.environment = environment;
		// --------------------------- Menu ----------------------------------------


		// Menu File Exit
		speed = new JSlider();
		speed.setMinimum(0);
		speed.setMaximum(100);
		speed.setPaintLabels(true);
		speed.setPaintTicks(true);
		speed.setMajorTickSpacing(10);
		speed.addChangeListener(this);
		speed.setSnapToTicks(true);

		speed.setFont(new Font("Serif", Font.PLAIN, 10));
		// Adds the menu components
		this.add(speed);


	}


	/**
	 * Invoked when the target of the listener has changed its state.
	 *
	 * @param e a ChangeEvent object
	 */
	@Override
	public void stateChanged(ChangeEvent e) {
		JSlider s = (JSlider) e.getSource();
		MobileRobot.delay = s.getValue();
		speed.setToolTipText("robot delay: " + s.getValue());
	}
}
